package ro.k.servlets.newOrder;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import ro.k.servlets.KConstants;
import ro.k.web.beans.ClientMasinaBean;

/**
 * Servlet implementation class ClientAndCarSave
 */
@WebServlet("/clientCarSave")
public class ClientAndCarSave extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public ClientAndCarSave() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		
		HttpSession sess = request.getSession();
		
		ClientMasinaBean cmb = (ClientMasinaBean) sess.getAttribute(KConstants.ClientCar);
		if(cmb==null){
			cmb = new ClientMasinaBean();
			cmb.setNume(request.getParameter("nume"));
			cmb.setAdresa(request.getParameter("adresa"));
			cmb.setTelefon(request.getParameter("telefon"));
			cmb.setMarca(request.getParameter("marca"));
			cmb.setNr(request.getParameter("nr"));
			cmb.setSeria(request.getParameter("serie"));
			cmb.setMotor(request.getParameter("motor"));
			
			sess.setAttribute(KConstants.ClientCar, cmb);
			
		}
		
		response.sendRedirect("jsp/requests.jsp");
	}

}
